import React, { Fragment } from 'react';
import { connect } from 'dva';
import BasePage from './BasePage'
import CurrentLocation from '../components/currentLocation'
import breadArr from '../constant/breadArr'
import { Timeline, Result, List, Button, Breadcrumb } from 'antd'
import { FileDoneOutlined } from '@ant-design/icons'
import style from '../assets/less/applicationLess.less'
import TechnologyTable from '../components/table/technologyTable'

class VerificationPage extends React.Component {
    constructor(props) {
        super(props),
            this.state = {
                data: []
            }
    }

    goToApplicationProcess = () => {
        this.props.dispatch({
            type:'application/setVerification',
            data:{
                verificationPhase:1,
                examinationStatus:-1
            }
        })

        this.props.dispatch({
            type: 'app/appMenuReplacePage',
            data: '/application/process'
        })
    }

    checkLogin = user => {
        if (user.userType == 1) {
            this.props.dispatch({
                type: 'application/getVerificationListByUserId',
                data: { userId: this.props.user.id }
            })
            
            return (
                <Fragment>
                    <Button id={style.applicationButton} type='primary' onClick={this.goToApplicationProcess}>申请验证</Button>
                    <div id={style.applicationList}>
                        <TechnologyTable></TechnologyTable>
                    </div>
                </Fragment>
            )
        }

        if (user.userType !== 1) {
            return (
                <Result
                    status="warning"
                    title="请先登录技术供应商账号后再查看技术验证！"
                >
                </Result>
            )
        }
    }

    render() {
        return (
            <BasePage>
                <CurrentLocation breadArr={breadArr.ApplicationPage}></CurrentLocation>
                {this.checkLogin(this.props.user)}
            </BasePage>
        )
    }
}

const mapStateToProps = state => {
    let user = state.app.user
    return {
        user
    }
}

export default connect(mapStateToProps)(VerificationPage)